// eee.Sheffield.PZ.Imaging
//
// Copyright ?Ping Zou, 2007
// sg71.cherub@gmail.com

using System;
using System.Collections.Generic;
using System.Text;
using eee.Sheffield.PZ.Math;
using System.Drawing;
using System.Drawing.Imaging;

namespace eee.Sheffield.PZ.Imaging.ImageFilter
{
    public class TaskFO
    {
        private Bitmap _srcImage;
        private Bitmap _manualImage;

        public TaskFO(Bitmap src, Bitmap manual)
        {
            _srcImage = src;
            _manualImage = manual;
        }

        public void FO()
        {
            // SIS
            SISThreshold sisFilter = new SISThreshold();
            sisFilter.ApplyGraylevelImageFilter(_srcImage);
            int sisThrehold = sisFilter.Threshold;

            int[] thresholdArray = new int[41];
            for (int i = 0; i < 20; i++)                
            {
                thresholdArray[i] = sisThrehold - 20 + i;
                thresholdArray[20 + i + 1] = sisThrehold + i + 1;
            }
            thresholdArray[20] = sisThrehold;

            for (int i = 0; i < 41; i++)
            {
                int threshold = thresholdArray[i];
                // threshold
                Threshold thresholdFilter = new Threshold(threshold);
                Bitmap thresholdImage = thresholdFilter.ApplyGraylevelImageFilter(_srcImage);
                // thin
                RockettThinning thinningFilter = new RockettThinning();
                Bitmap thinImage = thinningFilter.Apply(thresholdImage);
                // evaluate
                EvaluateThinningByManualSegmentation eval = new EvaluateThinningByManualSegmentation(thinImage, _manualImage);
                eval.EvaluateResult();     
                // output
                string output = "Threshold: " + threshold + " ";
                output += "F: " + eval.FValue + " ";
                output += "O: " + eval.OValue;
                Console.WriteLine(output);
            }
        } // FO()
    }
}
